package com.zxxnj;

import com.zxxnj.MyThreadPool.MyRejectedExecutionHandler;
import com.zxxnj.MyThreadPool.MyTaskQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Test {
    public static void main(String[] args) {
        ThreadPoolExecutor t = new ThreadPoolExecutor(1, 5, 10L, TimeUnit.SECONDS,
                new MyTaskQueue(2), new MyRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()));


        for(int i = 0; i < 10; ++i) {
            t.execute(() -> {
                try {
                    System.out.println(Thread.currentThread().getName() + ":start");
                    Thread.sleep(2000000L);
                } catch (InterruptedException var1) {
                    InterruptedException e = var1;
                    throw new RuntimeException(e);
                }
            });
        }

        System.out.println(Thread.currentThread().getName() + ":线程池队列大小：" + t.getQueue().size());
    }
}
